/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.ds2.Dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itsc.ds2.model.Student;

/**
 *
 * @student Juan Carlos
 */
@Stateless
public class StudentDao extends AbstractDao<Student> implements StudentDaoLocal {
    @PersistenceContext(unitName = "MusicSchoolStudentControl-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public StudentDao() {
        super(Student.class);
    }

    @Override
    public Boolean findDuplicity(Student student) {
    Query q = em.createNamedQuery("Student.findDuplicity");
        q.setParameter("id", student.getId());
        q.setParameter("name", student.getName());
        q.setParameter("firstname", student.getFirstname());
        q.setParameter("lastname", student.getLastname());
        return !q.getResultList().isEmpty();
    }
    
    
}
